﻿using MediatR;
using TaskProject.Application.Command.Production;
using TaskProject.Domain.Production;
using TaskProject.ErrorCode;
using TaskProject.InfrasIntructure.Interface;

namespace TaskProject.Application.Handler.Production
{
    public class GetProductItemHandler : IRequestHandler<GetProductItemCommand, APIResult<List<ProductItemModel>>>
    {
        IBaseRepository<ProductItemModel> proRepo;

        public GetProductItemHandler(IBaseRepository<ProductItemModel> proRepo)
        {
            this.proRepo = proRepo;
        }

        public Task<APIResult<List<ProductItemModel>>> Handle(GetProductItemCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<ProductItemModel>> res = new APIResult<List<ProductItemModel>>();
            var products = proRepo.GetAll().ToList();
            res.Msg = "查询产品信息成功";
            res.Code=APIEnum.Success;
            res.Data = products;
            return Task.FromResult(res);
        }
    }
}
